//---------------------------------------------------------------------------


#pragma hdrstop

#include <Math.h>
#include "TWeightLevel.h"

//---------------------------------------------------------------------------

#pragma package(smart_init)

int __fastcall TWeightLevel::GetLevel(const double AxesWeight)
{
	int i, q;
//	q = fabs(AxesWeight);
	if (AxesWeight < 0.001) return 0;
	q = size();
	for (i = 0; i < q; i++)
		if (AxesWeight < at(i)) return i + 1;
	return q + 1;
};

//---------------------------------------------------------------------------
bool __fastcall TWeightLevel::Initialize(const eMeasurementIndex Index, const vector<double> WeightNumbers)
{
	double t = 0;
//	MeasurementIndex = Index;
	for (int i = 0; i < WeightNumbers.size(); i++) {
		if (WeightNumbers[i] < t) return false;
		t = WeightNumbers[i];
		push_back(t);
	}
	return true;
};

//---------------------------------------------------------------------------
TWeightLevel & __fastcall TWeightLevel::operator = (const TWeightLevel & t)
{
//	MeasurementIndex = t.MeasurementIndex;
	clear();
	for (int i = 0; i < t.size(); i++) push_back(t[i]);
	return *this;
}
//---------------------------------------------------------------------------

void __fastcall TWeightLevel::SetDefault(const eMeasurementIndex MeasurementIndex)
{
	switch (MeasurementIndex) {
		case BritishMeasurement:
			resize(5);
			at(0) = 7.5;
			at(1) = 11.25;
			at(2) = 17.5;
			at(3) = 25;
			at(4) = 35;
			break;
		case MetricMeasurement:
		default:
			resize(3);
			at(0) = 7.5;
			at(1) = 11.25;
			at(2) = 17.5;
			break;
	}
	return;
}
//---------------------------------------------------------------------------
void __fastcall TWeightLevel::SetMetricDefault(void)
{
	resize(3);
//	MeasurementIndex = MetricMeasurement;
	at(0) = 7.5;
	at(1) = 11.25;
	at(2) = 17.5;
	return;
}

//---------------------------------------------------------------------------
void __fastcall TWeightLevel::SetBritishDefault(void)
{
	resize(5);
//	MeasurementIndex = BritishMeasurement;
	at(0) = 7.5;
	at(1) = 11.25;
	at(2) = 17.5;
	at(3) = 25;
	at(4) = 35;
	return;
}

//---------------------------------------------------------------------------
void __fastcall TWeightLevel::Read(TListItems *Items)
{
	clear();
	for (int i = 0; i < Items->Count; i++) {
		if (Items->Item[i]->Caption.IsEmpty()) continue;
		push_back(0.25 * StrToFloat(Items->Item[i]->Caption));
	}
	return;
}

//---------------------------------------------------------------------------
void __fastcall TWeightLevel::Write(TListItems *Items)
{
	TListItem *Item;
	Items->Clear();
	for (int i = 0; i < size(); i++) {
		Item = Items->Add();
		Item->Caption = FloatToStr(at(i));
	}
	return;
}

//---------------------------------------------------------------------------

int __fastcall TWeightLevel::GetQuantity(void)
{
	return size() + 1;
}

void __fastcall TWeightLevel::SetQuantity(const int Quantity)
{
	resize(Quantity - 1);
	return;
}


